<template>
    <div class="newsinfo-container">
        <h3 class="title">{{newsinfo.title}}</h3>
        <p class="subtitle">
            <span>发表时间:{{ newsinfo.time | dateFormat}}</span>
            <span>点击: {{newsinfo.click}}次</span>
        </p>
        <hr>
        <div class="content" v-html="newsinfo.content"></div>
        <!-- 评论子组件区域 -->
        <comment-box :id="id"></comment-box>
    </div> 
</template>

<script>
    // 导入子组件
    import comment from '../subcomponents/comment.vue'
    import { Toast } from 'mint-ui'
    export default{
        data() {
            return {
                id:this.$route.params.id,//将url地址中传递的id值挂载到data上,方便调用
                newsinfo : {
                    id:this.id,
                    title:"幸福",
                    click:0,
                    time:"2019-02-22 12:20:33",
                    content:"<a ><img  width='105' height='70' src='//n.sinaimg.cn/blog/transform/175/w105h70/20190227/AQcQ-htptaqf3563114.jpg' /><span>勾践卧薪尝胆地</span></a>"
                }//新闻对象
            }
        },
        created() {
    //         this.getNewsInfo()
        },
        methods: {
            getNewsInfo(){
                //获取新闻数据的方法
                this.$http.get(''+this.id).then(result=>{
                    if(result.body.status == 0){
                        this.newsinfo = result.body.message[0];
                    }else{
                        Toast('获取新闻详情数据失败')
                    }
                })
            }
        },
        components:{//用来注册子组件的节点
             'comment-box':comment
        }
    }
</script>

<style lang="scss">
    .newsinfo-container{
        padding: 0 4px; //上下不给,左右4像素
        .title{
            font-size: 16px;
            text-align: center;
            margin: 15px 0;
            color: red;
        }
        .subtitle{
            font-size: 13px;
            color: #226aff;
            display: flex;//左右对齐
             justify-content: space-between;
        }
        .content{
            font-size: 13px;
            line-height: 13px;
            img{
                width: 100%;
            }
        }
    }
</style>